find_package(FLTK)
find_package(ZLIB)
find_package(CURL)

set(SRC_FILES
    main.cc
    gui.cc
    gui.hh
	data_cache.cc
	data_cache.hh
	downloader.cc
	downloader.hh
    tsv_parser.cc
    tsv_parser.hh
    sqlite3.c
    sqlite3.h)
set(PKG_SRC_FILES
    pkg/pkg.c
    pkg/pkg.h
    pkg/pkg_out.c
    pkg/pkg_out.h
    pkg/pkg_pdb.c
    pkg/pkg_pdb.h
    pkg/pkg_psp.c
    pkg/pkg_psp.h
    pkg/pkg_sys.c
    pkg/pkg_sys.h
    pkg/pkg_utils.h
    pkg/pkg_zrif.c
    pkg/pkg_zrif.h)
set(SCRYPTO_SRC_FILES
    scrypto/aes.c
    scrypto/aes.h
    scrypto/aes_x86.c
    scrypto/base64.c
    scrypto/base64.h
    scrypto/sc_crc32.c
    scrypto/sc_crc32.h
    scrypto/sc_crc32_x86.c
    scrypto/sha256.c
    scrypto/sha256.h)
if(WIN32)
    set(SRC_FILES ${SRC_FILES} compat_strptime.c compat_strptime.h)
endif()
add_executable(FreePSS ${SRC_FILES} ${PKG_SRC_FILES} ${SCRYPTO_SRC_FILES})
set_source_files_properties(sqlite3.c PROPERTIES COMPILE_FLAGS "-DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS -DSQLITE_MAX_EXPR_DEPTH=0 -DSQLITE_OMIT_DECLTYPE -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_USE_ALLOCA")
if(NOT MSVC)
    set_source_files_properties(aes_x86.c PROPERTIES COMPILE_FLAGS "-maes -mssse3")
    set_source_files_properties(sc_crc32_x86.c PROPERTIES COMPILE_FLAGS "-mpclmul -msse4")
endif()
source_group(src FILES ${SRC_FILES})
source_group(pkg FILES ${PKG_SRC_FILES})
source_group(scrypto FILES ${SCRYPTO_SRC_FILES})
target_link_libraries(FreePSS ${FLTK_LIBRARIES} ${CURL_LIBRARIES} ${ZLIB_LIBRARIES})
target_include_directories(FreePSS PRIVATE ${FLTK_INCLUDE_DIR} ${CURL_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} scrypto)
if(WIN32)
    target_compile_options(FreePSS PRIVATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
	target_link_libraries(FreePSS shlwapi wldap32 crypt32 ws2_32)
endif()
